#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
using pii=pair<int,int>;
int m=0,n=0;
class Solution {
public:
    void bfs(vector<vector<char>>& board,int i,int j)
    {
        queue<pii> q;
        q.push({i,j});
        board[i][j]='Y';
        while(!q.empty())
        {
            int a=q.front().first;
            int b=q.front().second;
            q.pop();
            for(int k=0;k<4;k++)
            {
                int x=a+dx[k],y=b+dy[k];
                if(x>=0&&x<m&&y>=0&&y<n&&board[x][y]=='O')
                {
                    q.push({x,y});
                    board[x][y]='Y';
                }
            }
        }
    }
    void solve(vector<vector<char>>& board) 
    {
        m=board.size();
        n=board[0].size();
        for(int i=0;i<m;i++)
        {
            if(board[i][0]=='O')
            {
                bfs(board,i,0);
            }
            if(board[i][n-1]=='O')
            {
                bfs(board,i,n-1);
            }
        }
        for(int i=0;i<n;i++)
        {
            if(board[0][i]=='O')
            {
                bfs(board,0,i);
            }
            if(board[m-1][i]=='O')
            {
                bfs(board,m-1,i);
            }
        }
         /*for(auto a:board)
         {
             for(auto b:a)
             {
                 cout<<b<<" ";
             }
             cout<<endl;
         }*/
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(board[i][j]=='O') board[i][j]='X';
                if(board[i][j]=='Y') board[i][j]='O';
            }
        }
    }
};
int main()
{
    return 0;
}